import Vue from 'vue'
import VueRouter from 'vue-router'
import initStore from './store'
import routes from './router'
import Vuex from 'vuex'
import Cookies from 'js-cookie'
import AwesomePicker from 'vue-awesome-picker';
Vue.use(AwesomePicker)

import './agent.less'
window.Cookies = Cookies

Vue.use(Vuex)
Vue.use(VueRouter)

const Root = { template: `<keep-alive> <router-view></router-view> </keep-alive>` }
const router = new VueRouter({ routes })
const store = initStore()
const instance = new Vue({
  router,
  store,
  components: { Root },
  beforeMount() {
    this.$store.dispatch('getSelfInfo')
  }
})

$(function() {
  FastClick.attach(document.body);
})

function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}
const token = getQueryString('token');
const areaCode = getQueryString('areaCode');
Cookies.set('areaCode', areaCode)
Cookies.set('token', token)

instance.$mount('#root')

const btn_sound = document.createElement('audio');
btn_sound.setAttribute('src', 'http://c-c.jiahuagame.com/minigame/sound/down.mp3');
btn_sound.setAttribute('controls', 'controls');
btn_sound.setAttribute('hidden', 'true');
btn_sound.setAttribute('id', 'btn_sound');
document.body.appendChild(btn_sound);
window.btn_sound = btn_sound;
